package com.wavehi.login.advice;

import com.wavehi.login.common.AjaxResult;
import com.wavehi.login.exception.DataParamException;
import com.wavehi.login.exception.ParamException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description
 * @Author WaveHi
 * @Date 30/11/2021 下午 4:49
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 */
@ControllerAdvice
public class CommonExceptionController {

    @ExceptionHandler(ParamException.class)
    public void dealPE(Exception e) {
        e.printStackTrace();
    }

    @ExceptionHandler(DataParamException.class)
    @ResponseBody
    public AjaxResult dealDPE(Exception e) {
        e.printStackTrace();
        return AjaxResult.error(AjaxResult.CODE_ERROR,e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public AjaxResult dealRE(Exception e) {
        e.printStackTrace();
        return AjaxResult.error(AjaxResult.CODE_ERROR, AjaxResult.MSG_ERROR);
    }

}
